package com.cddx.logistics.controller;

import com.cddx.logistics.domain.vo.NewMaterialSummaryVo;
import com.cddx.logistics.service.NewMaterialSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/statistics/newMaterial")
public class NewMaterialSummaryController {

    @Autowired
    private NewMaterialSummaryService newMaterialSummaryService;

    @GetMapping("/summary")
    public List<NewMaterialSummaryVo> getMaterialSummary(
            @RequestParam(value = "materialName", required = false) String materialName,
            @RequestParam(value = "startDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(value = "endDate", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {

        return newMaterialSummaryService.getNewMaterialSummaryByCondition(
                materialName, startDate, endDate
        );
    }
}